﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2015 Jean-Marc VIGLINO, 
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Control Toggle</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="ol.control.Bar is a control bar that contains controls." />
  <meta name="keywords" content="ol3, control, bar, panel, ol3, openlayers, interaction" />

  <link rel="stylesheet" href="../style.css" />

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
  <!-- FontAwesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>
  
  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>

  <style>
    .ol-button i {
      color: inherit;
    }
    .ol-button.ol-active button {
      background: #9df;
    }
    .select {
      top:0.5em;
      right:50%;
    }
    .edit {
      top:0.5em;
      left:50%;
    }
  </style>

</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <a href="../../index.html">
    <h1>ol-ext: control Toggle</h1>
  </a>
  <div class="info">
    <i>ol.control.Toggle</i> is an <i>ol.control.Button</i> with an active/deactive state.
    <br/>
    If can be created with an <i>ol.interaction</i> and controls its activation.
    <br/>
    It can be grouped into an <a href="map.control.bar.html">ol.control.Bar</a> with a <i>toggleOne</i> propertie to have only one activated at a time. 
    You can compose toolbars with it (see the <a href="map.control.bar.html">control bar example</a>).
    <br/>
    When adding Toggle control to a bar, an option bar can be nested to add a subbar visible when the control is active (see the <a href="map.control.subbar.html">sub-bar example</a>).
  </div>

  <!-- Map div -->
  <div id="map" style="width:600px; height:400px;"></div>

  <div class="options" >
    Info:<br />
    <textarea id="info" style="width:25em; height:10em"></textarea>
    <br/>
    <input id="disable" type="checkbox" onchange="pedit.setDisable($(this).prop('checked'));" /><label for="disable"> disable edit control</label>
  </div>

  <script type="text/javascript">

    //  Vector layer
    var vector = new ol.layer.Vector( { source: new ol.source.Vector() })

    // The map
    var map = new ol.Map({
      target: 'map',
      view: new ol.View({
        zoom: 14,
        center: [270701, 6247637]
      }),
      layers: [
        new ol.layer.Tile({ source: new ol.source.OSM() }),
        vector
      ]
    });

    // Add selection tool (a toggle control with a select interaction)
    var selectCtrl = new ol.control.Toggle({
      html: '<i class="fa fa-hand-pointer-o"></i>',
      className: "select",
      title: "Select",
      interaction: new ol.interaction.Select (),
      active:true,
      onToggle: function(active) {
        $("#info").text("Select is "+(active?"activated":"deactivated"));
      }
    });
    map.addControl(selectCtrl);
    
    // Add editing tools
    var pedit = new ol.control.Toggle({
      html: '<i class="fa fa-map-marker" ></i>',
      className: "edit",
      title: 'Point',
      interaction: new ol.interaction.Draw({
        type: 'Point',
        source: vector.getSource()
      }),
      onToggle: function(active) {
        $("#info").text("Edition is "+(active?"activated":"deactivated"));
      }
    });
    map.addControl ( pedit );
    pedit.on("change:disable", function(e) {
      $("#info").text("Edition is "+(e.disable?"disabled":"enabled")); 
    });
    
  </script>

</body>
</html>